'''
Created on 2010-12-11

@author: Yaron
@summary: 1. How to Create a Panel In Frame;
          2. How to Create a Button In Panel;
          3. How to Bind Event On Button;
          4. How to Bind Custom Method On Close Event;
          5. How to Close Frame;
          6. How to Close App, This is Important ***
'''

# 1. import wx

# 2. Define Frame Class

# 3. Run App By wx.PySimpleAPP()

import wx

class InsertFrame(wx.Frame):
  
  def __init__(self, parent, id):
    # 2.1 Init wx.Frame Constructor function
    wx.Frame.__init__(self, parent, id, 'Frame With Button', size=(300, 200))
    # 2.2 Create Panel Object 
    panel = wx.Panel(self)
    # 2.3 Create Button Object In panel
    button = wx.Button(panel, label="close", pos=(100, 100), size=(40,20))
    # 2.4 Bind Event On button
    self.Bind(wx.EVT_BUTTON, self.OnCloseMe, button)
    # 2.5 Bind Close Window Method On Close Event
    self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
    
  # 2.6 def Close Method For Button
  def OnCloseMe(self, event):
    self.Close(True)
  
  # 2.7 Define Close Window Method For Close Event
  def OnCloseWindow(self, event):
    self.Destroy()
    
if __name__ == '__main__':
  app = wx.PySimpleApp()
  frame = InsertFrame(parent=None, id=-1)
  frame.Show()
  app.MainLoop()

  

